<template>
  <a-modal v-model="visible" :title="title" :confirmLoading="submitLoading" width="600px" ok-text="确认" cancel-text="取消"
    @ok="addFormSubmit">
    <a-form :form="events_form" :label-col="{ span: 8 }" :wrapper-col="{ span: 12 }">
      <a-form-item label="员工姓名">
        <a-input placeholder="请输入员工姓名" v-decorator="['name']"></a-input>
      </a-form-item>
      <a-form-item label="身份证号">
        <a-input placeholder="请输入身份证号" v-decorator="['idCard']"></a-input>
      </a-form-item>
      <a-form-item label="考勤时间">
        <a-date-picker valueFormat="YYYY-MM-DD" v-decorator="['attendanceTime']" placeholder="请选择日期" />
      </a-form-item>
      <a-form-item label="失业缴费基数">
        <a-date-picker valueFormat="YYYY-MM-DD" v-decorator="['attendanceTime']" placeholder="请选择日期" />
      </a-form-item>
      <a-form-item label="考勤时间段">
        <a-select v-decorator="['attendanceTimeType']" style="width: 120px;margin-right: 15px;" placeholder="选择状态">
          <a-select-option :key="1">
            早上
          </a-select-option>
          <a-select-option :key="2">
            下午
          </a-select-option>
        </a-select>
      </a-form-item>
      <a-form-item label="实际打卡日期">
        <a-date-picker valueFormat="YYYY-MM-DD HH:mm:ss" show-time v-decorator="['actualAttendanceTime']"
          placeholder="请选择日期" />
      </a-form-item>
      <a-form-item label="考勤状态">
        <a-select v-decorator="['attendanceStatus']" style="width: 120px;margin-right: 15px;" placeholder="选择状态">
          <a-select-option :key="1">
            正常
          </a-select-option>
          <a-select-option :key="2">
            迟到
          </a-select-option>
          <a-select-option :key="3">
            早退
          </a-select-option>
          <a-select-option :key="4">
            事假
          </a-select-option>
          <a-select-option :key="5">
            调休假
          </a-select-option>
          <a-select-option :key="6">
            旷工
          </a-select-option>
          <a-select-option :key="7">
            正常上班
          </a-select-option>
        </a-select>
      </a-form-item>
      <div v-if="id">
        <a-form-item label="残疾人姓名">
          <a-input placeholder="请输入残疾人姓名" v-decorator="['disabledName']"></a-input>
        </a-form-item>
        <a-form-item label="审核状态">
          <a-radio-group v-decorator="['examineStatus']">
            <a-radio :value="1">
              通过
            </a-radio>
            <a-radio :value="2">
              不通过
            </a-radio>
          </a-radio-group>
        </a-form-item>
        <a-form-item label="审核时间">
          <a-date-picker valueFormat="YYYY-MM-DD HH:mm:ss" show-time v-decorator="['examineTime']"
            placeholder="请选择日期" />
        </a-form-item>
      </div>
    </a-form>
  </a-modal>
</template>

<script>
import {
  updateAttendance
} from "@/api/human/disabled"
import store from '@/store'
import { mapGetters, mapActions } from 'vuex'
export default {
  name: 'AddInfo',
  data() {
    return {
      title: "",
      visible: false,
      submitLoading: false,

      id: "",
    }
  },
  beforeCreate() {
    this.events_form = this.$form.createForm(this, {
      name: 'events_form'
    });
  },
  computed: {
    ...mapGetters(['userInfo'])
  },
  methods: {
    // 打开编辑弹窗 
    async add(row) {
      this.visible = true;
      this.id = row === true ? '' : row.id;
      if (row == true) {
        this.title = '新增';
        this.$nextTick(() => {
          this.events_form.resetFields();
        })
      } else {
        this.title = '修改';
        this.$nextTick(() => {
          let values = this.events_form.getFieldsValue();
          for (var key in row) {
            values[key] = row[key]
          }
          this.events_form.setFieldsValue(values);
        })
      }
    },
    // 提交
    async addFormSubmit() {
      this.events_form.validateFieldsAndScroll(async (err, values) => {
        if (!err) {
          let params = {};
          if (this.id) {
            // 修改
            values.id = this.id;
            params = values;
          } else {
            // 新增
          }
          this.submitLoading = true;
          const { code } = this.id ? await updateAttendance(params) : await updateAttendance(params);
          this.submitLoading = false;
          if (code === '1') {
            this.visible = false;
            this.$message.success('操作成功');
            this.$emit('on-ok');
          }
        }
      });
    }
  }
}
</script>
